package com.heima.Controller;

import com.heima.Service.ScheduleSerice;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.pojos.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("Schedule/")
public class ScheduleController {
    @Autowired
    ScheduleSerice scheduleSerice;

    @PostMapping("add")
    public ResponseResult AddTask(@RequestBody Task task)
    {
        boolean flag = scheduleSerice.AddTask(task);
        return ResponseResult.okResult(flag);
    }

    @GetMapping("execute/{taskType}/{priority}")
    public ResponseResult ExecuteTask(@PathVariable("taskType") Integer taskType,@PathVariable("priority") Integer priority)
    {
        Task returntask = scheduleSerice.ExecuteTask(taskType,priority);
        return ResponseResult.okResult(returntask);
    }

    @GetMapping("delete/{id}")
    public ResponseResult DeleteTask(@PathVariable long id)
    {
        boolean flag = scheduleSerice.DeleteTask(id);
        return ResponseResult.okResult(flag);
    }
}
